package com.aaa.service.sas.impl;

import com.aaa.aspect.InsertAnn;
import com.aaa.aspect.UpdateAnn;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.sas.QuestionSas;
import com.aaa.dao.sas.QuestionSasDao;
import com.aaa.entity.scl.QuestionScl;
import com.aaa.service.sas.QuestionSasService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 问题表(QuestionSas)表服务实现类
 *
 * @author makejava
 * @since 2022-08-30 16:14:17
 */
@Service("questionSasService")
public class QuestionSasServiceImpl implements QuestionSasService {
    @Resource
    private QuestionSasDao questionSasDao;


    @Override
    public List<QuestionSas> queryAllQuestion(QuestionSas questionSas) {
        return questionSasDao.queryAllQuestion(questionSas);
    }

    /**
     * 分页查询
     *
     * @param pageSortEntity
     * @param questionSas
     * @return
     */
    @Override
    public Page queryQuestionPage(PageSortEntity pageSortEntity, QuestionSas questionSas) {
        PageHelper.startPage(pageSortEntity.getPage(), pageSortEntity.getLimit(), pageSortEntity.getOrderString());
        List<QuestionSas> questionSas1 = questionSasDao.queryAllQuestion(questionSas);
        Page<QuestionSas> page = (Page) questionSas1;
        return page;
    }

    /**
     * 添加数据
     *
     * @param questionSas
     * @return
     */
    @Override
    @InsertAnn
    public boolean saveQuestion(QuestionSas questionSas) {
        return questionSasDao.saveQuestion(questionSas);
    }


    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public QuestionSas queryById(Integer id) {
        return this.questionSasDao.queryById(id);
    }


    /**
     * 新增数据
     *
     * @param questionSas 实例对象
     * @return 实例对象
     */
    @InsertAnn
    @Override
    public QuestionSas insert(QuestionSas questionSas) {
        this.questionSasDao.insert(questionSas);
        return questionSas;
    }

    /**
     * 修改数据
     *
     * @param questionSas 实例对象
     * @return 实例对象
     */
    @UpdateAnn
    @Override
    public boolean update(QuestionSas questionSas) {
        return this.questionSasDao.update(questionSas);
    }

    /**
     * 删除数据
     *
     * @param id
     * @return
     */
    @Override
    public int delQuestion(int[] id) {
        List<Object> arrayList = new ArrayList<>();
        for (int i : id) {
            arrayList.add(i);
        }
        int i = questionSasDao.delQuestion(arrayList);
        return i;
    }

    /**
     * 查询所有问题
     *
     * @return
     */
    @Override
    public List<QuestionSas> findAllQuestion() {
        return questionSasDao.findAllQuestionByCondition();
    }

    @Override
    public List<QuestionSas> findAll(PageSortEntity pageSortEntity, QuestionSas questionSas) {
        PageHelper.startPage(pageSortEntity.getPage(), pageSortEntity.getLimit(), pageSortEntity.getOrderString());
        return questionSasDao.queryAllQuestion(questionSas);
    }

}
